﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace DataLibrary
{
    public class Ctbl_Language:IData<tbl_Language>
    {
        public Ctbl_Language(String myconnecString) : base(myconnecString) { }
        public override List<tbl_Language> GetAll(tbl_Language item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Language GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdLang == Convert.ToInt32(id));
        }

        public override tbl_Language GetItem(IDataReader dr)
        {
            tbl_Language obj = new tbl_Language();
            obj.IdLang = Convert.ToInt32(dr[tbl_Language.c_idLang]);
            obj.NameLang = Convert.ToString(dr[tbl_Language.c_nameLang]);
            obj.Value = Convert.ToString(dr[tbl_Language.c_value]);
            obj.IsActive = Convert.ToInt32(dr[tbl_Language.c_isActive]);
            return obj;
        }

        public override List<tbl_Language> GetAll()
        {
            String strSQL = "select * from " + tbl_Language.b_tbl_Language
                + " order by idLang desc";
            return GetAll(strSQL, CommandType.Text);
        }

        protected override int InsertOnSubmit(tbl_Language item, int t)
        {
            int id = -1;
            String strProName = "";
            id = connec.ExecuteNonQuery(strProName,CommandType.StoredProcedure,new SqlParameter("@flag",t),
                new SqlParameter("@"+tbl_Language.c_idLang,item.IdLang),new SqlParameter("@"+tbl_Language.c_isActive,item.IsActive),
                new SqlParameter("@"+tbl_Language.c_nameLang,item.NameLang),new SqlParameter("@"+tbl_Language.c_orderId,item.OrderId),
                new SqlParameter("@"+tbl_Language.c_value,item.Value));
            return id;
        }

    }
}
